﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Text;

public partial class BookInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {      
        if (Request.Form["lb"] != null)
        {
            Response.Clear();
            //书籍添加
            if (Request.Form["lb"].ToString() == "add")
            {
                if (Page.User.Identity.Name != "")
                {
                    string sUserName = Page.User.Identity.Name;
                    Book bookinfo = new Book();
                    bookinfo.BookName = Request.Form["bookname"].ToString();
                    bookinfo.BookRem = Request.Form["rem"].ToString();
                    bookinfo.BookWriter = Request.Form["writer"].ToString();
                    bookinfo.BookType = Request.Form["booktype"].ToString();
                    bookinfo.BookCover = Request.Form["coverurl"].ToString();
                    //增加新书籍，返回新书的记录号
                    int iBookID = BookManger.newBook(bookinfo, sUserName);

                    Response.Write(iBookID.ToString());
                }
                else
                {
                    Response.Write("尚未登录");
                }
            }
            //改变类型
            if (Request.Form["lb"].ToString() == "changetype")
            {
                if (Page.User.Identity.Name != "")
                {
                    string sUserName = Page.User.Identity.Name;
                    Book bookinfo = new Book();
                    bookinfo.BookID = Request.Form["bookid"].ToString();
                    bookinfo.BookTypeID = Request.Form["booktype"].ToString();

                    if (BookManger.changeType(bookinfo, sUserName))
                    {
                        Response.Write("感谢您的关注");
                        //重建页面
                        WebMake.buildBookPage(bookinfo.BookID, -1);
                    }
                    else
                        Response.Write("您今天改过它的类型或者今日更改次数上限制");
                }
                else
                {
                    Response.Write("尚未登录");
                }

            }
            if (Request.Form["lb"].ToString() == "ticketit")
            {
                if (Page.User.Identity.Name != "")
                {
                    string sUserName = Page.User.Identity.Name;
                    string sBookID = Request.Form["bookid"].ToString();

                    if (BookManger.ticketIt(sBookID, sUserName))
                    {
                        Response.Write("感谢您的投票");
                        //重建页面
                        WebMake.buildBookPage(sBookID, -1);
                    }
                    else
                        Response.Write("您今天已经给它投票过或者今天可用投票数已用完");
                }
                else
                {
                    Response.Write("尚未登录");
                }
            }
            else if (Request.Form["lb"].ToString() == "checkbook" && Request.Form["bookname"] != null)
            {
                string sBookName = Request.Form["bookname"].ToString();
                if (BookManger.checkBook(sBookName))
                    Response.Write("false");
                else
                    Response.Write("true");
            }
            Response.End();
            
        }
    }
}
